package org.bluedream.core.utils.thymeleaf;

import org.springframework.stereotype.Component;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.dialect.IProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;

import java.util.HashSet;
import java.util.Set;

/**
 * Thymeleaf 自定义注解
 */
@Component
public class ThymeleafEntrance extends AbstractProcessorDialect implements IProcessorDialect {
    // 定义方言名称
    private static final String DIALECT_NAME = "thl-dialect";
    // 要应用于名称的匹配前缀
    private static final String PREFIX = "thl";

    public ThymeleafEntrance() {
        super(DIALECT_NAME, PREFIX, StandardDialect.PROCESSOR_PRECEDENCE);
    }

    /**
     * 元素处理器
     * @param s
     * @return
     */
    @Override
    public Set<IProcessor> getProcessors(String s) {
        Set<IProcessor> processors = new HashSet<IProcessor>();
        processors.add(new ThymeleafProcessor(PREFIX));
        return processors;
    }
}
